// pages/mySpace/information/information.js
const app=getApp()
Page({

  data: {
    id:1,
    name:'',
    wxid:'',
    company_type:'',
    city:'',
    address:'',
    telephone:'',
    openid:'',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const that=this
    wx.request({
      url: `http://localhost:8080/user/getMyMsg?WXID=${app.WXID}`,
      header: {
        'content-type': 'application/json' // 默认值
      }, 
      success (res) {
        // console.log("user",res.data[0])
        let user=res.data[0]
        // console.log(user)
        const {id,name,wxid,company_type,city,address,telephone}=user
        that.setData({id,name,wxid,company_type,city,address,telephone})
        console.log(id,name,wxid,company_type,city,address,telephone)
      }
    })
  },
  
  submitForm(){
    console.log("user",this.data.telephone)
    wx.request({
      url: `http://localhost:8080/user/changeuserinfo`,
      method:"POST",
      data:{
        id:this.data.id,
        name:this.data.name,
        wxid:this.data.wxid,
        company_type:this.data.company_type,
        city:this.data.city,
        address:this.data.address,
        telephone:this.data.telephone,
      },
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 默认值
      }, 
      success (res) {
        wx.redirectTo({
          url: '../../market/puechase-result/index'
        })
      }
    })
  }
})